﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_Tra_Project_contract : System.Web.UI.Page
{
    static public string strProjectMarker, strTitle, strContent;
    static string ProjectId;
    
    protected void Page_Load(object sender, EventArgs e)
    {

        string strHospitalName = "";


        if (Request.QueryString["ProjectId"] != null)
        {
            ProjectId = SysFun.IsSQL(Request.QueryString["ProjectId"].ToString());
        }
        else
        {
            ProjectId = "1";
        }

        if (!IsPostBack)
        {
            Db DbProject = new Db();

            string strSql = "Select projectid,Contract_star_time,Contract_end_time,ProjectMarker,Title,Content,ProjectHabitus,Hospitals,AccountId from Project where ProjectId=" + ProjectId.ToString();
            System.Data.IDataReader dr = DbProject.DataReader(strSql);

            if (dr.Read())
            {

                strProjectMarker = dr["ProjectMarker"].ToString();
                strTitle = dr["Title"].ToString();
                strContent = dr["Content"].ToString();
                if ((dr["Contract_star_time"]).ToString() != "")
                {
                    txtcontractStartDate.Text = (dr["Contract_star_time"]).ToString().Remove(dr["Contract_star_time"].ToString().Length - 7);
                }
                if ((dr["Contract_end_time"]).ToString() != "")
                {
                    txtcontractEndDate.Text = (dr["Contract_end_time"]).ToString().Remove(dr["Contract_end_time"].ToString().Length - 7);
                }
                txtProjectHabitus.Text = HZ.MBSM.BLL.ProjectHabitus.GetProjectHabitus((HZ.MBSM.BLL.enumProjectHabitus)(int.Parse(dr["ProjectHabitus"].ToString())));
                strHospitalName = dr["Hospitals"].ToString();
            }
            dr.Close();
            dr.Dispose();
            strSql = "select accountid,hospitalname,area.areaname from hospital left join area on hospital.areaid=area.areaid where accountid  in (" + strHospitalName.Replace("'", "") + ")  order by area.areaname ";
            dr = DbProject.DataReader(strSql);
            //DataList1.DataSource = dr;
            //DataList1.DataBind();
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            int k = 1, j = 0;
            string AreaName = "";
            sb.Append("<table width='98%' cellspacing='0' border='1' cellpadding='3'>");
            while (dr.Read())
            {
                if (dr["hospitalname"].ToString() == "沙洋县人民医院")
                    k = k;
                if (AreaName != SysFun.ToTrim(dr["AreaName"]))
                {
                    AreaName = SysFun.ToTrim(dr["AreaName"]);
                    if (j != 0)
                    {

                        switch (k % 4)
                        {
                            case 0:
                                sb.Append("</tr>");
                                break;
                            case 3:
                                sb.Append("<td>&nbsp;</td></tr>");
                                break;
                            case 2:
                                sb.Append("<td>&nbsp; </td><td>&nbsp; </td></tr>");
                                break;
                            case 1:
                                sb.Append("<td>&nbsp; </td><td> &nbsp;</td><td> &nbsp;</td></tr>");
                                break;

                        }
                    }
                    j = 1;
                    k = 1;
                    sb.Append("<tr>");
                    sb.Append("<td colspan=3 style='color: #ff0033'>" + dr["AreaName"].ToString() + "</td>");
                    sb.Append("</tr>");
                    sb.Append("<tr>");
                }
                else
                {
                    if (k % 4 == 0)
                    {
                        j = 1;
                        k = 1;

                        sb.Append("</tr><tr>");
                    }
                }
                sb.Append("<td>" + dr["hospitalname"].ToString() + "</td>");

                k++;

            }
            switch (k % 4)
            {
                case 0:
                    sb.Append("</tr>");
                    break;
                case 3:
                    sb.Append("<td>&nbsp;</td></tr>");
                    break;
                case 2:
                    sb.Append("<td>&nbsp; </td><td>&nbsp; </td></tr>");
                    break;
                case 1:
                    sb.Append("<td>&nbsp; </td><td> &nbsp;</td><td> &nbsp;</td></tr>");
                    break;

            }

            sb.Append("<table>");
            Label4.Text = sb.ToString();
            dr.Close();
            dr.Dispose();
            DbProject.Close();

        }
    }
    protected void Button1_Click(object sender, EventArgs e)　//保存
    {
        
        DateTime StartDate1, EndDate1;
       
        if (txtcontractStartDate.Text != "")
            StartDate1 = Convert.ToDateTime(txtcontractStartDate.Text.ToString());
        else
            StartDate1 = Convert.ToDateTime("2006-1-1");
        if (txtcontractEndDate.Text != "")
            EndDate1 = Convert.ToDateTime(txtcontractEndDate.Text.ToString());
        else
            EndDate1 = Convert.ToDateTime("2006-1-1");
        if (EndDate1 <= StartDate1)
        {
            Response.Write("<script>alert('结束时间不能小于或等于开始时间！');</script>");
        }
        else
        {
            string str = "update project set Contract_star_time='" + StartDate1 + "', Contract_end_time='" + EndDate1 + "' where ProjectId=" + ProjectId.ToString();
            Db db = new Db();
            db.Command(str);
            db.Close();

            Response.Write("<script>alert('保存成功！');</script>");
        }
    }
}
